var app = require("app");
cc.Class({
    extends: require("BaseForm"),

    properties: {
        diamondImg: [cc.SpriteFrame],
    },

    OnCreateInit: function () {
        this.leftStr = cc.find("sp_buy/left/btn_table/title", this.node);
        this.rightLayout = cc.find("sp_buy/right/scrollView/view/layout", this.node);
        this.demoNode = this.node.getChildByName("demo");
        this.demoNode.active = false;
        //测试用
        this.demo = {
            "type": "钻石",
            "coin": "￥",
            "config": [
                {
                    "cos": 6,
                    "get": 30,
                }
            ],
        }
    },

    OnShow: function () {
        app.NetManager().SendPack("base.getStoreConfig", {}, this.RefreshConfig.bind(this), () => {
            app.SysNotifyManager().ShowSysMsg("无此功能");
            this.CloseForm();
        });
    },

    RefreshConfig(serverPack) {
        //serverPack = this.demo;
        this.leftStr.getComponent(cc.Label).string = serverPack.type;
        for (let i = 0; i < serverPack.config.length; i++) {
            if (i >= 8) continue;
            let tempNode = cc.instantiate(this.demoNode);
            tempNode.active = true;
            tempNode.getChildByName("cos").getComponent(cc.Label).string = serverPack.coin + serverPack.config[i].cos;
            tempNode.getChildByName("get").getComponent(cc.Label).string = serverPack.config[i].get + serverPack.type;
            tempNode.getChildByName("img").getComponent(cc.Sprite).spriteFrame = this.diamondImg[i];
            this.rightLayout.addChild(tempNode);
        }
    },
    OnClick: function (btnName, btnNode) {

    },

});